package com.demo.aop;

import android.Manifest;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.aspectj.aop.annotation.ArgsNullCheck;
import com.aspectj.aop.annotation.EventTrack;
import com.aspectj.aop.annotation.InsertLog;
import com.aspectj.aop.annotation.RequirePermission;
import com.aspectj.aop.annotation.SingleClick;
import com.aspectj.aop.annotation.TryCatch;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    public static final String TAG = "LOG_NOW";
    private TextView msg;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        msg = findViewById(R.id.msg);
    }

    @EventTrack(what = 10, value = {"参数1", "参数2"})
    public void eventTrack(View view) {
        Log.i(TAG, "this is a EventTrack click log.");
    }


    public void insertLog(View view) {
        getPersonalInfo(20, "boy");
    }

    int count = 0;
    @SingleClick(value = 4000, ids = {R.id.singleClick})
    public void singleClick(View view) {
        Log.i(TAG, "this is a single click log.");
        ++count;
        msg.setText("count=" + count);
    }


    @RequirePermission(value = {Manifest.permission.WRITE_EXTERNAL_STORAGE })
    public void requirePermission(View view) {
        Log.i(TAG, "this is a RequirePermission click log.");
    }

    @TryCatch
    public void tryCatch(View view) {
        Log.i(TAG, "this is a ArgsNullCheck click log.");
        int value = 1 / 0;
    }

    @ArgsNullCheck(args = { 1 })
    public void argsNullCheck(View view) {
        Log.i(TAG, "this is a ArgsNullCheck click log.");
        getPersonalInfo(20, null);
    }

    @ArgsNullCheck(args = { 1 })
    @InsertLog
    public int getPersonalInfo(int age, String name) {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return age + 20;
    }



}





